import java.util.Arrays;

public class MyStack {
    public int[] elem;
    public int usedSize;

    public MyStack(){
        this.elem=new int[10];
    }
    public void push(int val){
        if(isFull()){
            elem= Arrays.copyOf(elem,2*elem.length);
        }

        elem[usedSize]=val;
        usedSize++;
    }

    public boolean isFull(){
        return usedSize==elem.length;
    }

    public int pop(){
        if (isEmpty()){
            return -1;
        }
        int oldVal=elem[usedSize-1];
        usedSize--;//如果是引用类型要加一句：elem[usedSize]=null;
        return oldVal;
    }

    public int peek(){
        if (isEmpty()){
            return -1;
        }
        return elem[usedSize-1];
    }


    public boolean isEmpty(){
        return usedSize==0;
    }
}
